/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spring.modelo.DAO;

import com.spring.modelo.entidad.Docente;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author karolyn
 */
@Repository
public class DocenteDAO extends HibernateDaoSupport{
    @Autowired   
    public DocenteDAO(SessionFactory sf){
        super.setSessionFactory(sf);
    }
    public boolean insertarDocentes(Docente d){
        boolean flag=false;
        try{
            getHibernateTemplate().saveOrUpdate(d);
            flag=true;
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return flag;
    }
    
    public List<Docente> listarDocentes(){
        return getHibernateTemplate().findByNamedQuery("Docente.findAll");
    }
    
    public Docente buscarDocente(String codigo){
        return getHibernateTemplate().get(Docente.class, codigo);
    }
    
    public boolean eliminarDocente(String codigo){
        boolean flag=false;
        try{
            getHibernateTemplate().delete(buscarDocente(codigo));
            flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }
        return flag;
    }
    
}
